require "Common/define"
require "Logic/Config"
require "Common/functions"

TowerRecordItemList = {};
HelperFunc.SetUIEnv(TowerRecordItemList)
local this = TowerRecordItemList;

this.gameObject = nil;
this.transform = nil;
this.LuaBehaviour = nil;

this.playerName = nil;
this.power = nil;
this.time = nil;
this.heroList = nil;
this.btn_Play = nil;
this.btn_skada = nil;        --战斗统计

function TowerRecordItemList.initData(obj,data)
    -- gameObject = obj;
    -- transform = obj;

    playerName = obj:GetChild("PlayerName")-- :GetComponent("TextMeshProUGUI");
    power = obj:GetChild("power")-- :GetComponent("TextMeshProUGUI");
    time = obj:GetChild("time")-- :GetComponent("TextMeshProUGUI");
    heroList = obj:GetChild("heroList");

    btn_Play = obj:GetChild("btn_player")
    btn_skada = obj:GetChild("btn_skada")
    btn_icon = obj:GetChild("icon")
    img_head = obj:GetChild("icon"):GetChild("head"):GetChild("HeadIcon")
    img_frame = obj:GetChild("icon"):GetChild("frame")

    if data ~= nil then
        playerName.text = data["playerName"];
        local cur_power_str = HelperFunc.FormatResourceNum(data["power"], true)
        power.text = cur_power_str;
        local serverTime = os.date("%Y.%m.%d %H:%M:%S",tonumber(data["time"])/1000);
        time.text = "通关时间："..serverTime;

        --btn_icon.onClick:Clear();
        --btn_icon.onClick:Add(function()
        --    if tostring(data.playerId) ~= logicMgr.HeroManager.GetRoleId() then
        --        roleInfoHandler.sendreqOtherRoleInfo(data.playerId);
        --    end
        --end)
        local path = dataTable.getDataTableByStringId("t_skin",data.icon,"f_HeroIcon")
        HelperFunc.SetIcon(img_head,path,EnumConst.ItemShowType.ICON)
        img_frame.url = "ui://ICONAtlas/" .. data.headFrame
        local heroDataList = {};
        heroDataList = data["heroList"];

        heroList:RemoveChildrenToPool();
        -- local head = getUI(PanelNames.HeadRectItem);
        local ctrl = CtrlManager.GetCtrl(PanelNames.HeadRectItem);
        for i = 1, #heroDataList do
            local headObj = heroList:AddItemFromPool()
            local heroconfig = G.dataTable["t_hero"][tostring(heroDataList[i].partnerModelId)];
            local data = {}
            logicMgr.HeroManager.copyHeroConfig(heroconfig, data);
            data.level = heroDataList[i].level;
            data.star = heroDataList[i].star;
            data.quality = heroDataList[i].quality;
            if ctrl ~= nil then  --初始装备信息
                ctrl.initData(headObj,data);
                headObj.touchable = false;
            end
        end
    end

end




return TowerRecordItemList;